package org.jeecg.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.wms.entity.WmsSupplierContact;
import org.jeecg.modules.wms.mapper.WmsSupplierContactMapper;
import org.jeecg.modules.wms.service.IWmsSupplierContactService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 供应商联系人表
 * @Author: jeecg-boot
 * @Date: 2023-07-18
 * @Version: V1.0
 */
@Service
public class WmsSupplierContactServiceImpl extends ServiceImpl<WmsSupplierContactMapper, WmsSupplierContact> implements IWmsSupplierContactService {

    @Override
    public List<WmsSupplierContact> listBySupplier(String supplierId) {
        LambdaQueryWrapper<WmsSupplierContact> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmsSupplierContact::getSupplierId, supplierId);
        return this.list(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveBatch(String supplierId, List<WmsSupplierContact> contactList) {
        // 设置供应商ID
        contactList.forEach(contact -> contact.setSupplierId(supplierId));
        return this.saveBatch(contactList);
    }

    @Override
    public boolean deleteBySupplier(String supplierId) {
        LambdaQueryWrapper<WmsSupplierContact> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmsSupplierContact::getSupplierId, supplierId);
        return this.remove(queryWrapper);
    }
} 